package 复习.博客2;

import java.util.ArrayList;
import java.util.List;

public class 组合 {
    List<List<Integer>> lists = new ArrayList<>();
    List<Integer> list = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
        backStacking(n,k,1);
        return lists;
    }

    public void backStacking(int n,int k,int index){
        if(list.size() == k){
            lists.add(new ArrayList<>(list));
            return;
        }

        for(int i = index;i <= n;i++){
            list.add(i);
            backStacking(n,k,i + 1);
            list.remove(list.size() - 1);
        }
    }
}

/*
class Solution {
    List<List<Integer>> lists = new ArrayList<>();
    List<Integer> list = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
        backStacking(n,k,1);
        return lists;
    }

    public void backStacking(int n,int k,int index){
        if(list.size() == k){
            lists.add(new ArrayList<>(list));
        }
        for (int i = index; i <= n; i++) {
            list.add(i);
            backStacking(n,k,i+1);
            list.remove(list.size() - 1);
        }
    }
}
 */
